Page({
  data: {
    imageList: [],
    videoList: [],
    audioPath: '',
    textContent: '',
    isPlaying: false,
    recipient: '',
    Sender: '',
    Time: ''
  },

  onLoad(options) {
    if (options.images) {
      this.setData({
        imageList: JSON.parse(options.images)
      });
    }

    if (options.videos) {
      this.setData({
        videoList: JSON.parse(options.videos)
      });
    }

    if (options.audio) {
      this.setData({
        audioPath: decodeURIComponent(options.audio)
      });
    }

    if (options.text) {
      this.setData({
        textContent: decodeURIComponent(options.text)
      });
    }

    if (options.recipient) {
      this.setData({
        recipient: options.recipient
      });
    }

    if (options.Sender) {
      this.setData({
        Sender: options.Sender
      });
    }

    if (options.Time) {
      this.setData({
        Time: options.Time
      });
    }
  },

  togglePlayRecording() {
    const innerAudioContext = wx.createInnerAudioContext();
    innerAudioContext.src = this.data.audioPath;

    if (this.data.isPlaying) {
      innerAudioContext.stop();
      this.setData({ isPlaying: false });
    } else {
      innerAudioContext.play();
      this.setData({ isPlaying: true });
    }

    innerAudioContext.onEnded(() => {
      this.setData({ isPlaying: false });
    });

    innerAudioContext.onStop(() => {
      this.setData({ isPlaying: false });
    });
  }
});
